package cn.lastcrdg.testresultreceiver;

import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.widget.TextView;

/**
 * author：liluo
 * e-mail：lastcrazysun@163.com
 * company：cusc
 * date：2017/11/28 15:39
 * description：
 */

public class ResultData extends ResultReceiver {
    private TextView mTextView;

    /**
     * Create a new ResultReceive to receive results.  Your
     * {@link #onReceiveResult} method will be called from the thread running
     * <var>handler</var> if given, or from an arbitrary thread if null.
     *
     * @param handler
     */
    public ResultData(Handler handler) {
        super(handler);
    }

    public ResultData(Handler handler, TextView textView) {
        super(handler);
        mTextView = textView;
    }

    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
        super.onReceiveResult(resultCode, resultData);
        if (MainActivity.REQUEST_CODE == resultCode){
            String result_second = resultData.getString("result_second");
            mTextView.setText(mTextView.getText().toString().trim() + "--" + result_second);
        }
    }
}
